package com.yami.shop.api.controller;

import com.yami.shop.bean.app.dto.IndexImgDto;
import com.yami.shop.bean.app.dto.NoticeDto;
import com.yami.shop.bean.model.BannerImage;
import com.yami.shop.bean.model.IndexImg;
import com.yami.shop.bean.model.Notice;
import com.yami.shop.service.BannerImageService;
import com.yami.shop.service.ConfigService;
import com.yami.shop.service.IndexImgService;
import com.yami.shop.service.NoticeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import ma.glasnost.orika.MapperFacade;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/p/picture")
@Api(tags = "首页轮播图接口")
public class HomePictureController {
    @Autowired
    private MapperFacade mapperFacade;

    @Autowired
    private IndexImgService indexImgService;

    @Autowired
    private NoticeService noticeService;

    @Autowired
    private ConfigService configService;

    @Autowired
    private BannerImageService bannerImageService;

    /**
     * 首页轮播图接口
     */
    @GetMapping("/homePicture")
    @ApiOperation(value = "首页轮播图", notes = "获取首页轮播图列表信息")
    public ResponseEntity<List<IndexImgDto>> homePicture() {
        Long shopId = Long.valueOf(0);
        List<IndexImg> indexImgList = indexImgService.listIndexImgs(shopId);
        List<IndexImgDto> indexImgDtos = mapperFacade.mapAsList(indexImgList, IndexImgDto.class);
        return ResponseEntity.ok(indexImgDtos);
    }

    //首页数据获取
    @GetMapping("/homePageData")
    public ResponseEntity<Map> homePageData(){
        Map map = new HashMap();
        //首页公告
        Long shopId = Long.valueOf(0);
        List<Notice> noticeList = noticeService.listNotice(shopId);
        List<NoticeDto> noticeDtos = mapperFacade.mapAsList(noticeList, NoticeDto.class);
        map.put("noticeList",noticeDtos);
        //首页轮播图
        List<IndexImg> indexImgList = indexImgService.listIndexImgs(shopId);
        List<IndexImgDto> indexImgDtos = mapperFacade.mapAsList(indexImgList, IndexImgDto.class);
        map.put("indexList",indexImgDtos);
        //获取背景图片
        BannerImage bannerImage = bannerImageService.getBannerImage();
        map.put("backgroundImage",bannerImage);
        return ResponseEntity.ok(map);
    }

}
